// ===========================================================================
// KinectDevice.h : Header file for KinectDevice class
// ---------------------------------------------------------------------------
// Copyright (C) 2011 by Kevin Fisher
// ---------------------------------------------------------------------------
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// Author: Kevin Fisher <fisher.kevin.g -at- gmail.com> 
// Date:   Sat Aug 13 2011 15:15 EST
// ============================================================================

#ifndef KINECTDEVICE_H_
#define KINECTDEVICE_H_

// ============================================================================

#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <libfreenect.hpp>

#include "Mutex.h"

// ============================================================================ 

/// <summary>
/// Creates an adapter class to the freenect library's cpp wrapper.
/// </summary>
/// <remarks>
/// This class should not be modified directly, instead it is recommended to
/// create a sub-class
/// </remarks>
class KinectDevice
	: public Freenect::FreenectDevice
{
public:
	KinectDevice(freenect_context *ctx, int index);
	virtual ~KinectDevice(void);

	// --[ WARNING ]-----------------------------------------------------------
	// Do Not call directly, even in child.
	// ------------------------------------------------------------------------
	virtual void VideoCallback(void *p_rgb, uint32_t timestamp);
	virtual void DepthCallback(void *p_depth, uint32_t timestamp);
	// ------------------------------------------------------------------------
	
	virtual bool getRGB(uint8_t buffer[]);
	virtual bool getDepth(uint8_t buffer[]);

	static const int RGB_WIDTH;
	static const int RGB_HEIGHT;
	static const int DEPTH_WIDTH;
	static const int DEPTH_HEIGHT;
	static const int BUFFER_SIZE;

protected:
	std::vector<uint8_t>         buffer_depth;
	std::vector<uint8_t>         buffer_video;
	std::vector<uint16_t>         gamma;

	Mutex                        rgb_mutex;
	Mutex                        depth_mutex;

	bool                         new_rgb_frame;
	bool                         new_depth_frame;

private:

};

// ============================================================================ 

#endif //KINECTDEVICE_H_ //

// ============================================================================ 

// ------------------------------[ END OF CODE ]-------------------------------

/// \file KinectDevice.h
/// \author Kevin Fisher <fisher.kevin.g -at- gmail.com> 
/// \date \c Created: Sat Aug 13 2011 15:18 EST

